import { Mesh } from "three";
import Three from "./index";

// Amf 实例化
export class Damper extends Three {
  // 初始化
  constructor(dom: HTMLElement, openGUI: boolean = false) {
    super(dom, openGUI);
  }

  // 添加模型
  async addDamper() {
    const params = {
      rotateZ: 30, // 风门打开角度 0-90
    };
    const damper = await this.addGltf("/model/damper.glb");
    const door1 = damper.children.find(
      (child) => child.name === "door1",
    ) as Mesh;
    const door2 = damper.children.find(
      (child) => child.name === "door2",
    ) as Mesh;
    door1.rotation.z = (params.rotateZ * Math.PI) / 180;
    door2.rotation.z = (params.rotateZ * Math.PI) / 180;

    if (door1 && this.gui) {
      const folder = this.gui.addFolder("风门");
      folder
        .add(params, "rotateZ", 0, 90, 1)
        .name("door1")
        .onChange((value) => {
          door1.rotation.z = (value * Math.PI) / 180;
        });
      folder
        .add(params, "rotateZ", 0, 90, 1)
        .name("door2")
        .onChange((value) => {
          door2.rotation.z = (value * Math.PI) / 180;
        });
    }
  }
}
